package cn.eslm.flash.api.controller.system;

import cn.eslm.flash.api.controller.BaseController;
import cn.eslm.flash.bean.core.ShiroUser;
import cn.eslm.flash.bean.vo.front.Rets;
import cn.eslm.flash.bean.vo.node.MenuNode;
import cn.eslm.flash.bean.vo.node.RouterMenu;
import cn.eslm.flash.cache.TokenCache;
import cn.eslm.flash.service.system.MenuService;
import cn.eslm.flash.utils.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Autowired
    private MenuService menuService;
    @Autowired
    private TokenCache tokenCache;

    @RequestMapping(value = "/listForRouter", method = RequestMethod.GET)
    public Object listForRouter() {
        ShiroUser shiroUser = tokenCache.getUser(HttpUtil.getToken());

        List<RouterMenu> list = menuService.getSideBarMenus(shiroUser.getRoleList());
        return Rets.success(list);
    }
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Object list() {
        List<MenuNode> list = menuService.getMenus();
        return Rets.success(list);
    }


}
